package com.logicwin.aibala.action;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.zip.ZipException;

import com.logicwin.aibala.model.androidSWInfo.APKListItem;
import com.logicwin.aibala.services.file.FileConnection;
import com.logicwin.aibala.services.net.NetConnection;
import com.logicwin.aibala.services.xml.XMLParser;
import com.logicwin.aibala.services.zip.ZipUtil;

public class LoadListAction implements Runnable{
	
	private String getListUrl = 
			"http://www.logicwin.com/aibala/getSoftwareList.php?userId=0&screenWidth=0&screenHeight=0&type=0&subtype=0&filter=0&time=20110730111030&sort=1&page=1";
	
	private LoadListListener _listener = null;
	
	public boolean startLoad(LoadListListener listener){
		_listener = listener;
		new Thread(this).start();
		return true;
	}

	@Override
	public void run() {
		String zipPath =  NetConnection.httpGet(getListUrl, null);
		NetConnection.downLoadFile(zipPath, FileConnection.getCurrentPath()+"/temp.zip");
		try {
			ZipUtil.upZipFile(new File(FileConnection.getCurrentPath()+"/temp.zip"), FileConnection.getCurrentPath());
		} catch (ZipException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String xmlPath = zipPath.substring(zipPath.lastIndexOf("/")+1,zipPath.length()-4)+".xml";
		List<APKListItem> apkList = XMLParser.parseList(FileConnection.getCurrentPath()+"/"+xmlPath);
		
		//_listener.loadListTextDone();
	}
}
